using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GameMenu : MonoBehaviour
{
	public static bool restartMainMenu;

	public ScreenMenu screenMainMenu;

	public GameResult gameResult;

	public Text textVersionGame;

	public UnityEvent restartScene;

	public Button quitGameButton;

	private void Start()
	{
		textVersionGame.text = Application.productName + " " + Application.version;
		quitGameButton.onClick.AddListener(Quit);
		if (restartMainMenu)
		{
			restartScene.Invoke();
		}
		restartMainMenu = true;
		if (gameResult != null && gameResult.isShowed)
		{
			OnShowResult();
		}
		else if (gameResult != null)
		{
			gameResult.show.AddListener(OnShowResult);
		}
		screenMainMenu.Show();
	}

	private void OnDestroy()
	{
		PlayerPrefsFile.Save();
	}

	public void OnShowResult()
	{
		SwitchUI.ShowScene(gameResult.gameObject);
	}

	public void Quit()
	{
		Application.Quit();
	}

	public void LoadScene(string sceneName)
	{
		SceneManager.LoadScene(sceneName);
	}

	public void LoadScene(int sceneId)
	{
		SceneManager.LoadScene(sceneId);
	}

	public void SceneReset()
	{
		SceneManager.LoadScene(SceneManager.GetActiveScene().name);
	}

	public void OpenURL(string url)
	{
		Application.OpenURL(url);
	}
}
